import { IFeidaoAiNodejsComponent } from '@feidao/web/interfaces';

import P01 from './P01';
import P02 from './P02';
import P03 from './P03';

import nodejs from '@feidao/web/atom/nodejs/msg-b/nodejs';
import render from '@feidao/web/atom/nodejs/render/render';

export default async function nba001(fd: IFeidaoAiNodejsComponent, ...args: any[]) {
	// 组件初始化
	console.log('zj-manage-001 init n', args);
	let page_no = fd.data.params['page_no'];
	if (!page_no) {
		page_no = 1;
	}
	let page_size = fd.data.params['page_size'];
	if (!page_size) {
		page_size = 20;
	}
	const c = fd.data.params.param;
	const query = {
		criteria: c ? c : {},
		page_no,
		page_size
	};
	const res = await nodejs(fd.data.spaceid, "exam_find", query);
	if (res.count == 0) {
		render(fd.data.node, '', P02, 'P02');
	} else {
		render(fd.data.node, res.dataArray, P01, 'P01');
	}
	res['page_size'] = page_size;
	render(fd.data.node, res, P03, 'P03');
}
